package com.ruoyi.web.plan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.web.plan.domain.TaskInfo;
import com.ruoyi.web.plan.service.IDutyService;
import com.ruoyi.web.plan.service.ITaskInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 任务列表Controller
 *
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/task/info")
public class TaskInfoController extends BaseController {
    @Autowired
    private ITaskInfoService taskInfoService;
    @Autowired
    private IDutyService dutyService;

    /**
     * 查询任务列表列表
     */
    @SaCheckPermission("task:info:list")
    @GetMapping("/list")
    public AjaxResult list(TaskInfo taskInfo) {
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        return success(list);
    }

    /**
     * 导出任务列表列表
     */
    @SaCheckPermission("task:info:export")
    @Log(title = "任务列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskInfo taskInfo) {
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        ExcelUtil<TaskInfo> util = new ExcelUtil<TaskInfo>(TaskInfo.class);
        util.exportExcel(response, list, "任务列表数据");
    }

    /**
     * 获取任务列表详细信息
     */
    @SaCheckPermission("task:info:query")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
        return success(taskInfoService.selectTaskInfoByTaskId(taskId));
    }

    /**
     * 新增任务列表
     */
    @SaCheckPermission("task:info:add")
    @Log(title = "任务列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskInfo taskInfo) {
        return toAjax(taskInfoService.insertTaskInfo(taskInfo));
    }


    /**
     * 修改任务列表
     */
    @SaCheckPermission("task:info:edit")
    @Log(title = "任务列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskInfo taskInfo) {
        return toAjax(taskInfoService.updateTaskInfo(taskInfo));
    }

    /**
     * 修改任务列表父子联动
     */
    @SaCheckPermission("task:info:edit")
    @Log(title = "任务列表", businessType = BusinessType.UPDATE)
    @PostMapping("/changeTasks")
    public AjaxResult changeTasks(@RequestBody TaskInfo taskInfo) {
        return toAjax(taskInfoService.updateTaskInfo(taskInfo));
    }

    /**
     * 删除任务列表
     */
    @SaCheckPermission("task:info:remove")
    @Log(title = "任务列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds) {
        return toAjax(taskInfoService.deleteTaskInfoByTaskIds(taskIds));
    }
}
